package io.gitee.chearnee.fw.dingtalk.property;

import jakarta.annotation.PostConstruct;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.Setter;
import org.springframework.boot.context.properties.ConfigurationProperties;

import java.util.Set;
import java.util.stream.Collectors;

/**
 * @author cn
 * @version 1.0
 * @description
 * @date 2021/7/27 20:09
 */

@Getter
@Setter
@ConfigurationProperties("dingtalk.config")
public class DingTalkProperties {

  /**
   * baseUrl
   */
  private String baseServerUrl;
  /**
   * accessToken and secret configs
   */
  private Set<DingTalkConfig> configs;

  @PostConstruct
  public void initConfig() {
    if (null != configs) {
      Set<String> configNames = configs.stream().map(DingTalkConfig::getName)
          .collect(Collectors.toSet());
      if (configNames.size() != configs.size()) {
        throw new RuntimeException("dingTalk configs name must be one,but found more than one");
      }
    }
  }

  @Getter
  @Setter
  @EqualsAndHashCode
  public static class DingTalkConfig {
    /**
     * 是否开启
     */
    private boolean enable = true;

    /**
     * config's name
     */
    private String name;
    /**
     * accessToken
     */
    private String accessToken;
    /**
     * secret
     */
    private String secret;
//    /**
//     * 艾特人的手机号
//     */
//    private Set<String> atPhones;
  }
}
